The user part of a tramp file name can be omitted. Usually, it is
replaced by the user name you are logged in. Often, this is not
what you want. A typical use of tramp
might be to edit some files with root permissions on the local
host. This case, you should set the variable
tramp-default-user to reflect that choice. For
example:
(setq tramp-default-user "root")
tramp-default-user is regarded as obsolete, and
will be removed soon.
You can also
specify different users for certain method/host combinations, via
the variable tramp-default-user-alist. For example,
if you always have to use the user ‘john’ in the domain
‘somewhere.else’, you can specify the
following:
(add-to-list 'tramp-default-user-alist
'("ssh" ".*\\.somewhere\\.else\\'" "john"))
See the documentation for the variable
tramp-default-user-alist for more details.
One trap to fall in must be known. If tramp finds a default user, this user will be passed always to the connection command as parameter (for example ‘ssh here.somewhere.else -l john’. If you have specified another user for your command in its configuration files, tramp cannot know it, and the remote access will fail. If you have specified in the given example in ~/.ssh/config the lines
Host here.somewhere.else
User lily
than you must discard selecting a default
user by tramp. This will be done by
setting it to nil (or ‘lily’, likewise):
(add-to-list 'tramp-default-user-alist
'("ssh" "\\`here\\.somewhere\\.else\\'" nil))
The last entry in tramp-default-user-alist could
be your default user you'll apply predominantly. You shall
append it to that list at the end:
(add-to-list 'tramp-default-user-alist '(nil nil "jonas") t)